package concurrent.automic;

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

/**
 * \* User: Administrator
 * <p>
 * \* Date: 2020/11/25
 * <p>
 * \* Time: 15:29
 * <p>
 * \* Description:
 * \
 */
public class AtomicFileldUpdaterDemo {
    public static void main(String[] args) throws InterruptedException {
        Alex alex = new Alex();
        AtomicIntegerFieldUpdater<Alex> updater = AtomicIntegerFieldUpdater.newUpdater(Alex.class, "a");
        for (int i = 0; i < 20000; i++) {
            new Thread(()->{
//                alex.setA(alex.getA() + 1);
                updater.addAndGet(alex, 1);
            }).start();
        }

        Thread.sleep(3000);
        System.out.println(updater.get(alex));
    }
}
